package FrameWork;
import java.awt.event.*;
import java.util.ArrayList;

import Input.*;
import Main.SpaceGame;
import Menus.*;

public class Input implements KeyListener
{
	public SpaceGame main;
	private SideMenuInput sideMenuInput;
	private DesignationMenuInput designationMenuInput;
	private BuildMenuInput buildMenuInput;
	private FullAnnouncementMenuInput fullAnnouncementMenuInput;
	private BuildingMenuInput buildingMenuInput;
	private HireMenuInput hireMenuInput;
	private ViewMenuInput viewMenuInput;
	private FireMenuInput fireMenuInput;
	public Input(SpaceGame main)
	{
		this.main = main;
	}
	
	public void keyPressed(KeyEvent e)
	{
		if(!main.gameOver)
		{
			ArrayList<Menu> topMenus = main.menuManager.getTopMenus();
			for(Menu m:topMenus)
			{
				if (m.getClass().getSimpleName().equals("SideMenu"))
				{
					sideMenuInput = new SideMenuInput(main);
					sideMenuInput.keyPressed(e);
				}
				else if (m.getClass().getSimpleName().equals("DesignationMenu"))
				{
					designationMenuInput = new DesignationMenuInput(main,(DesignationMenu) m);
					designationMenuInput.keyPressed(e);
				}
				else if (m.getClass().getSimpleName().equals("BuildMenu"))
				{
					buildMenuInput = new BuildMenuInput(main,(BuildMenu) m);
					buildMenuInput.keyPressed(e);
				}
				else if (m.getClass().getSimpleName().equals("FullAnnouncementMenu"))
				{
					fullAnnouncementMenuInput = new FullAnnouncementMenuInput(main, (FullAnnouncementMenu)m);
					fullAnnouncementMenuInput.keyPressed(e);
				}
				else if (m.getClass().getSimpleName().equals("BuildingMenu"))
				{
					buildingMenuInput = new BuildingMenuInput((BuildingMenu)m);
					buildingMenuInput.keyPressed(e);
				}
				else if (m.getClass().getSimpleName().equals("HireMenu"))
				{
					hireMenuInput= new HireMenuInput(main, (HireMenu)m);
					hireMenuInput.keyPressed(e);
				}
				else if (m.getClass().getSimpleName().equals("FireMenu"))
				{
					fireMenuInput= new FireMenuInput((FireMenu)m);
					fireMenuInput.keyPressed(e);
				}
			}
			
			
			
			
			if (!main.menuManager.hasFullMenu())
			{
			
				if (e.getKeyCode() == KeyEvent.VK_LEFT)
				{
					if (main.camera.canMove())
						main.camera.cameraLeft();
					if (main.cursor.isActive())
						main.cursor.moveLeft();
					/**
					 * This stuff is for movement of cameras and cursors.
					 */
				}
				
				else if (e.getKeyCode() == KeyEvent.VK_RIGHT)
				{
					if (main.camera.canMove())
						main.camera.cameraRight();
					if (main.cursor.isActive())
						main.cursor.moveRight();
					/**
					 * This stuff is for movement of cameras and cursors.
					 */
				}
				
				else if (e.getKeyCode() == KeyEvent.VK_UP)
				{
					if (main.camera.canMove())
						main.camera.cameraUp();
					if (main.cursor.isActive())
						main.cursor.moveUp();
					/**
					 * This stuff is for movement of cameras and cursors.
					 */
				}
				
				else if (e.getKeyCode() == KeyEvent.VK_DOWN)
				{
					if (main.camera.canMove())
						main.camera.cameraDown();
					if (main.cursor.isActive())
						main.cursor.moveDown();
					/**
					 * This stuff is for movement of cameras and cursors.
					 */
				}
				
				else if (e.getKeyCode() == KeyEvent.VK_SPACE)
				{
					main.setPaused();
				}
				
				for(Menu m:topMenus)
				{
					if (m.getClass().getSimpleName().equals("ViewMenu"))
					{
						viewMenuInput = new ViewMenuInput((ViewMenu)m);
						viewMenuInput.keyPressed(e);
					}
				}
			}
			
			if (e.getKeyCode() == KeyEvent.VK_ESCAPE)
			{
				main.menuManager.closeLevel();
				main.cursor.setCursorSize(1, 1);
				main.cursor.setDesignating(false);
			}
		}
	}

	
	public void keyReleased(KeyEvent e) 
	{
		
	}

	
	public void keyTyped(KeyEvent e) 
	{
		
	}
	
}

